package com.jlnk.stockdemo.bean;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class StockDetailResponse {

    @SerializedName("request_id")
    private String requestId;

    @SerializedName("code")
    private int code;

    @SerializedName("data")
    private Data data;

    @SerializedName("msg")
    private String msg;

    public String getRequestId() {
        return requestId;
    }

    public int getCode() {
        return code;
    }

    public Data getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    public static class Data {
        @SerializedName("fields")
        private List<String> fields;

        @SerializedName("items")
        private List<List<String>> items;

        @SerializedName("has_more")
        private boolean hasMore;

        @SerializedName("count")
        private int count;

        private List<StockDetail> stockDetailList;

        public List<String> getFields() {
            return fields;
        }

        public List<List<String>> getItems() {
            return items;
        }

        public boolean isHasMore() {
            return hasMore;
        }

        public int getCount() {
            return count;
        }

        public List<StockDetail> getStockDetailList() {
            stockDetailList = new ArrayList<>();
            int tradeDateIndex, openIndex, highIndex, lowIndex, closeIndex,
                    preCloseIndex, changeIndex, pctChgIndex, volIndex, amountIndex;
            tradeDateIndex = openIndex = highIndex = lowIndex = closeIndex = preCloseIndex
                    = changeIndex = pctChgIndex = volIndex = amountIndex = 0;
            for (int i = 0; i < fields.size(); i++) {
                switch (fields.get(i)) {
                    case "trade_date" :
                        tradeDateIndex = i;
                        break;
                    case "open" :
                        openIndex = i;
                        break;
                    case "high" :
                        highIndex = i;
                        break;
                    case "low" :
                        lowIndex = i;
                        break;
                    case "close" :
                        closeIndex = i;
                        break;
                    case "pre_close" :
                        preCloseIndex = i;
                        break;
                    case "change" :
                        changeIndex = i;
                        break;
                    case "pct_chg" :
                        pctChgIndex = i;
                        break;
                    case "vol" :
                        volIndex = i;
                        break;
                    case "amount" :
                        amountIndex = i;
                        break;
                }
            }
            for (int j = 0; j < items.size(); j++) {
                StockDetail stockDetail = new StockDetail();
                stockDetail.setTrade_date(items.get(j).get(tradeDateIndex));
                stockDetail.setOpen(items.get(j).get(openIndex));
                stockDetail.setHigh(items.get(j).get(highIndex));
                stockDetail.setLow(items.get(j).get(lowIndex));
                stockDetail.setClose(items.get(j).get(closeIndex));
                stockDetail.setPre_close(items.get(j).get(preCloseIndex));
                stockDetail.setChange(items.get(j).get(changeIndex));
                stockDetail.setPct_chg(items.get(j).get(pctChgIndex));
                stockDetail.setVol(items.get(j).get(volIndex));
                stockDetail.setAmount(items.get(j).get(amountIndex));
                stockDetailList.add(stockDetail);
            }
            return stockDetailList;
        }

        public static class StockDetail {
            // 交易日期
            private String trade_date;
            // 开盘价
            private String open;
            // 最高价
            private String high;
            // 最低价
            private String low;
            // 收盘价
            private String close;
            // 昨收价
            private String pre_close;
            // 涨跌额
            private String change;
            // 涨跌幅
            private String pct_chg;
            // 成交量
            private String vol;
            // 成交额
            private String amount;

            public String getTrade_date() {
                return trade_date;
            }

            public void setTrade_date(String trade_date) {
                this.trade_date = trade_date;
            }

            public String getOpen() {
                return open;
            }

            public void setOpen(String open) {
                this.open = open;
            }

            public String getHigh() {
                return high;
            }

            public void setHigh(String high) {
                this.high = high;
            }

            public String getLow() {
                return low;
            }

            public void setLow(String low) {
                this.low = low;
            }

            public String getClose() {
                return close;
            }

            public void setClose(String close) {
                this.close = close;
            }

            public String getPre_close() {
                return pre_close;
            }

            public void setPre_close(String pre_close) {
                this.pre_close = pre_close;
            }

            public String getChange() {
                return change;
            }

            public void setChange(String change) {
                this.change = change;
            }

            public String getPct_chg() {
                return pct_chg;
            }

            public void setPct_chg(String pct_chg) {
                this.pct_chg = pct_chg;
            }

            public String getVol() {
                return vol;
            }

            public void setVol(String vol) {
                this.vol = vol;
            }

            public String getAmount() {
                return amount;
            }

            public void setAmount(String amount) {
                this.amount = amount;
            }
        }
    }
}
